
#pragma once

#include "gamemessage.h"

#include <string>
#include <map>
#include <queue>

using namespace std;

#define SEND_MSG_ARGS(sender, receiver, key, value)				MessageQueue::getInstance()->send(GameMessage(sender, receiver, key, value))
#define SEND_MSG(s)												MessageQueue::getInstance()->send(s)
#define PEEK_MSG(s)												MessageQueue::getInstance()->peek(s)
#define POP_MSG(s)												MessageQueue::getInstance()->pop(s)

class MessageQueue {
public:
	static MessageQueue* getInstance();
	~MessageQueue();

	void send(const GameMessage& msg);
	GameMessage * peek(const char* holderName);
	void pop(const char* holderName);
	void clear(const char* target = "all");

private:
	MessageQueue();
	static MessageQueue* _instance;

	void init();
	
	map<const char*, queue<GameMessage> > _mapMessageHolders;
};
